package cn.szzsi.common.model;

import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.model.base.BaseIntegralOrders;

import java.util.Date;
import java.util.List;

/**
 * Created by haotian on 2017/2/7.
 */
public class IntegralOrders extends BaseIntegralOrders<IntegralOrders> {
    public static final IntegralOrders dao=new IntegralOrders().dao();

    public String saveOrders(String customerId, String productId, String name, String phone, String province, String city, String area, String address, Integer salesXin){
        IntegralOrders integralOrders=new IntegralOrders();
        integralOrders.set("id", CommonUtil.getUUID());
        integralOrders.set("customerId",customerId);
        integralOrders.set("productId",productId);
        integralOrders.set("name",name);
        integralOrders.set("phone",phone);
        integralOrders.set("province",province);
        integralOrders.set("city",city);
        integralOrders.set("area",area);
        integralOrders.set("address",address);
        integralOrders.set("orderStatus",0);
        integralOrders.set("salesXin",salesXin);
        integralOrders.set("createDate",new Date());
        integralOrders.save();
        return integralOrders.getStr("id");
    }

    public List<IntegralOrders> getByCustomerId(String customerId){
        List<IntegralOrders> list= IntegralOrders.dao.find("select * from mall_integral_orders where customerId=? order by createDate desc",customerId);
        return list;
    }

    public void init(){
        String productId=this.getStr("productId");
        IntegralProduct integralProduct= IntegralProduct.dao.findById(productId);
        this.put("productName",integralProduct == null?"":integralProduct.getStr("name"));
        this.put("allAddress",this.getStr("province")+"&nbsp;&nbsp;"+this.getStr("city")+"&nbsp;&nbsp;"+this.getStr("area")+"&nbsp;&nbsp;"+this.getStr("address"));
    }


    public List<IntegralOrders> getByCustomerIdAndProductId(String customerId, String productId){
        List<IntegralOrders> list= IntegralOrders.dao.find("select * from mall_integral_orders where customerId=? and productId=?",customerId,productId);
        return list;
    }

}






















